package com.ruoyi.test.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.test.domain.ProductOrders;
import com.ruoyi.test.service.IProductOrdersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产计划Controller
 * 
 * @author hzy
 * @date 2022-11-07
 */
@RestController
@RequestMapping("/test/productOrders")
public class ProductOrdersController extends BaseController
{
    @Autowired
    private IProductOrdersService productOrdersService;

    /**
     * 查询生产计划列表
     */
    @PreAuthorize("@ss.hasPermi('test:productOrders:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductOrders productOrders)
    {
        startPage();
        List<ProductOrders> list = productOrdersService.selectProductOrdersList(productOrders);
        return getDataTable(list);
    }

    /**
     * 导出生产计划列表
     */
    @PreAuthorize("@ss.hasPermi('test:productOrders:export')")
    @Log(title = "生产计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductOrders productOrders)
    {
        List<ProductOrders> list = productOrdersService.selectProductOrdersList(productOrders);
        ExcelUtil<ProductOrders> util = new ExcelUtil<ProductOrders>(ProductOrders.class);
        util.exportExcel(response, list, "生产计划数据");
    }

    /**
     * 获取生产计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('test:productOrders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productOrdersService.selectProductOrdersById(id));
    }

    /**
     * 新增生产计划
     */
    @PreAuthorize("@ss.hasPermi('test:productOrders:add')")
    @Log(title = "生产计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductOrders productOrders)
    {
        return toAjax(productOrdersService.insertProductOrders(productOrders));
    }

    /**
     * 修改生产计划
     */
    @PreAuthorize("@ss.hasPermi('test:productOrders:edit')")
    @Log(title = "生产计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductOrders productOrders)
    {
        return toAjax(productOrdersService.updateProductOrders(productOrders));
    }

    /**
     * 删除生产计划
     */
    @PreAuthorize("@ss.hasPermi('test:productOrders:remove')")
    @Log(title = "生产计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productOrdersService.deleteProductOrdersByIds(ids));
    }
}
